package com.haha.community.controller;


import com.haha.community.annotation.LoginRequire;
import com.haha.community.entity.Comment;
import com.haha.community.service.CommentService;
import com.haha.community.util.HostHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Yang
 * @since 2020-10-30
 */
@Controller
@RequestMapping("/comment")
public class CommentController {
    private static Logger logger = LoggerFactory.getLogger(CommentController.class);
    @Autowired
    private HostHolder hostHolder;
    @Autowired
    private CommentService commentService;
    @LoginRequire
    @RequestMapping(path = "/add/{discussPostId}", method = RequestMethod.POST)
    public String addComment(@PathVariable("discussPostId") int discussPostId, Comment comment) {
        comment.setUserId(hostHolder.getUser().getId());
        comment.setStatus(0);
        comment.setCreateTime(new Date());
        int i = commentService.addComment(comment);
        return "redirect:/discuss/detail/" + discussPostId;
    }

}

